using System;
using System.Globalization;

namespace PickGold.Charting.Design
{
	internal class LegendCellColumnCollectionEditor : ChartCollectionEditor
	{
		public LegendCellColumnCollectionEditor()
			: base(typeof(LegendCellColumnCollection))
		{
		}

		protected override object CreateInstance(Type itemType)
		{
			if ((base.Context != null) && (base.Context.Instance != null))
			{
				Legend instance = base.Context.Instance as Legend;
				if (instance != null)
				{
					int num = instance.CellColumns.Count + 1;
					string str = "Column" + num.ToString(CultureInfo.InvariantCulture);
					bool flag = true;
					while (flag)
					{
						flag = false;
						foreach (LegendCellColumn column in instance.CellColumns)
						{
							if (column.Name == str)
							{
								flag = true;
							}
						}
						if (flag)
						{
							num++;
							str = "Column" + num.ToString(CultureInfo.InvariantCulture);
						}
					}
					LegendCellColumn column2 = new LegendCellColumn();
					column2.Name = str;
					return column2;
				}
			}
			return base.CreateInstance(itemType);
		}
	}
}

